<script type="text/javascript">
	head.ready(function() {
		$('#file_upload').uploadify({
			'swf'  			: 'lib/js/uploadify/uploadify.swf',
			'uploader'  	: 'lib/js/uploadify/uploadify.php?album_id=<?php echo $album_id?>',
			'cancelImage' 	: 'lib/js/uploadify/cancel.png',
			'checkExisting' : 'lib/js/uploadify/uploadify-check-exists.php',
			'auto'			: true,
			'multi'			: true,
			'buttonText'	: 'Đăng ảnh',
			'onUploadComplete' : function( file ){
				insertImage (file.name);
			},
			'onUploadError'	: function (file,errorCode,errorMsg){
				alert(errorMsg);
			}
		});
	});

	function insertImage( file_name ){
		var album_id = '<?php echo $album_id;?>';
		str_arr = { album: album_id, image_name: file_name };
		encode_image_name = callAjaxFunction('?a=ACC&acc=USER&user=ALBU&albu=IM',str_arr);
		arr_info = encode_image_name.split('_');
		if (encode_image_name != '0')
			displayImage (file_name , arr_info[1] +'_'+arr_info[2],arr_info[0]);
	}
	
	function displayImage( file_name, encode_image_name, image_id ){
		var image_name = $.trim(encode_image_name);
		if ( image_name != '0' ){
			img = '<img class="album_img" id="img_' + image_id + '" onload="resize(\'' + 'img_' + image_id + '\')" src ="<?php echo URL?>lib/upload/thum/' + image_name + '" /> ';
			delete_btn = '<div class="img_action"><a class="button" onclick="deleteImage(\'' + image_id + '\')" href="javascript:void(0)"><?php echo _IMAGE_DELETE_IMAGE ?></a></div>';
			edit = '<div style="padding-top:30px"><div class="img_name button" id="dsp_' + image_id + '" onclick="showEdit(\'' + image_id + '\')" >' + displayLongText(file_name,<?php echo MAX_LENGTH_DISPLAY ?>) + ' <?php echo _IMAGE_EDIT_IMAGE ?></div><br/><div class="edit_input" id="edit_' + image_id + '"><input id="' + image_id + '" class="input w140" type="text" value="' + file_name + '" onchange="updateInput(this)"><a id="btn_back_' + image_id + '"onclick="hideEdit(\'' + image_id + '\')" href="javascript:void(0)"><?php echo _IMAGE_BACK_IMAGE ?></a></div></div>';			
			used_as_avatar = '<div><input class="checkbox_status" id="status_' + image_id + '" onclick="updateStatus(\'' + image_id + '\')" type="checkbox" > <?php echo _LB_DISPLAY_IN_HOMEPAGE; ?> </div>';
			html = '<li id="img_content_' + image_id + '"><div align="center" class="img_content">' + img + delete_btn + '</div>' + edit + '<br/> ' + used_as_avatar + '</li>';
			$('#album_image_content').append(html);
		}
	}

	function updateInput( obj ){
		var id = obj.id;
		var value = obj.value;
		str_arr = { img_id: id , img_name : value };
		callAjaxFunction('?a=ACC&acc=USER&user=ALBU&albu=UI',str_arr);
		new_name = displayLongText(value,<?php echo MAX_LENGTH_DISPLAY ?>);
		$('#dsp_'+id).html( new_name + '<?php echo _IMAGE_EDIT_IMAGE ?>');
		hideEdit(id);
	}

	function deleteImage( image_id ){
		if( !confirm("<?php echo _MSG_CONFIRM_DELETE_IMAGE; ?>") )
		{
			return false;
		}
		str_arr = { img_id : image_id};
		if ( callAjaxFunction('?a=ACC&acc=USER&user=ALBU&albu=DI',str_arr) ){
			$('#img_content_'+image_id).fadeOut();
			$('#img_content_'+image_id).remove();
		}
	}
	
	function updateStatus( image_id ){
		$(".checkbox_status").prop("checked", false);
		$('#status_'+image_id).prop("checked", true);
		if ( $('#status_'+image_id).is(':checked') ){
			str_arr = { img_id : image_id };
			callAjaxFunction('?a=ACC&acc=USER&user=ALBU&albu=US',str_arr);
		}	
	}
</script>

<br/><br/>
<input id="file_upload" type="file" name="file_upload" />
<br/><br/>
<div class="title">
	<a href="?a=ACC&acc=USER&user=ALBU"> <?php echo getAlbumName($album_id);?></a>
</div>
<br/>
<div class="left content_right">

<?php 
	echo $v_display_image;
?>
</div>
<div class="clear">&nbsp;</div>